supply a US-ASCII QTextCodec.
authortsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 27 Sep 2014 15:31:49 +0000 (15:31 +0000)
committertsteven4 <tsteven4@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 27 Sep 2014 15:31:49 +0000 (15:31 +0000)
gpsbabel/Makefile.in
gpsbabel/main.cc
gpsbabel/src/core/usasciicodec.cc [new file with mode: 0644]
gpsbabel/src/core/usasciicodec.h [new file with mode: 0644]

index 751a9417f9be3895aff8eb233ee0e7ca8580ba47..8c6c643a32a8d6c01d545471400e48a29ad3bcad 100644 (file)
@@ -111,6 +111,7 @@ LIBOBJS = queue.o route.o waypt.o filter_vecs.o util.o vecs.o mkshort.o \
           formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \
          inifile.o garmin_fs.o gbsleep.o units.o @GBSER@ gbser.o \
          gbfile.o parse.o session.o src/core/xmlstreamwriter.o \
+         src/core/usasciicodec.o \
        $(PALM_DB) $(GARMIN) $(JEEPS) $(SHAPE) @ZLIB@ $(FMTS) $(FILTERS)
 OBJS = main.o globals.o $(LIBOBJS) @FILEINFO@
 
@@ -444,7 +445,7 @@ cet.o: cet.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
   cet.h cet_util.h inifile.h session.h src/core/datetime.h
 cet_util.o: cet_util.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
-  cet/ansi_x3_4_1968.h cet/cp1252.h
+  cet/ansi_x3_4_1968.h cet/cp1252.h cet/iso_8859_8.h
 compegps.o: compegps.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
   csv_util.h jeeps/gpsmath.h jeeps/gpsport.h
@@ -452,11 +453,11 @@ cst.o: cst.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
   cet.h cet_util.h inifile.h session.h src/core/datetime.h strptime.h
 csv_util.o: csv_util.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
-  csv_util.h grtcirc.h strptime.h jeeps/gpsmath.h jeeps/gpsport.h \
-  garmin_fs.h jeeps/gps.h jeeps/gpsdevice.h jeeps/gpssend.h \
-  jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
-  jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmem.h jeeps/gpsrqst.h \
-  jeeps/gpsinput.h jeeps/gpsproj.h xcsv_tokens.gperf
+  csv_util.h garmin_fs.h jeeps/gps.h jeeps/gpsport.h jeeps/gpsdevice.h \
+  jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h \
+  jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h \
+  jeeps/gpsmem.h jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h \
+  grtcirc.h src/core/logging.h strptime.h xcsv_tokens.gperf
 delbin.o: delbin.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h \
   src/core/xmltag.h
@@ -795,7 +796,7 @@ magproto.o: magproto.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   magellan.h gbser.h explorist_ini.h
 main.o: main.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
   cet.h cet_util.h inifile.h session.h src/core/datetime.h filterdefs.h \
-  csv_util.h
+  csv_util.h src/core/usasciicodec.h
 mapasia.o: mapasia.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   gbfile.h cet.h cet_util.h inifile.h session.h src/core/datetime.h
 mapbar_track.o: mapbar_track.cc defs.h config.h queue.h zlib/zlib.h \
@@ -919,6 +920,7 @@ smplrout.o: smplrout.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h \
   filterdefs.h grtcirc.h
 sort.o: sort.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
   cet.h cet_util.h inifile.h session.h src/core/datetime.h filterdefs.h
+src/core/usasciicodec.o: src/core/usasciicodec.cc src/core/usasciicodec.h
 src/core/xmlstreamwriter.o: src/core/xmlstreamwriter.cc \
   src/core/xmlstreamwriter.h
 stackfilter.o: stackfilter.cc defs.h config.h queue.h zlib/zlib.h \
index 2cbf9507a8818b730dfe158764397c8d63791fae..59eb24cae4284b0e5bba6147e094bc3fe297179a 100644 (file)
@@ -26,6 +26,7 @@
 #include "csv_util.h"
 #include "inifile.h"
 #include "session.h"
+#include "src/core/usasciicodec.h"
 #include <ctype.h>
 #include <signal.h>
 
@@ -41,7 +42,7 @@ typedef struct arg_stack_s {
 } arg_stack_t;
 
 static arg_stack_t
-*push_args(arg_stack_t* stack, const int argn, const int argc, char* argv[])
+* push_args(arg_stack_t* stack, const int argn, const int argc, char* argv[])
 {
   arg_stack_t* res = (arg_stack_t*) xmalloc(sizeof(*res));
 
@@ -54,7 +55,7 @@ static arg_stack_t
 }
 
 static arg_stack_t
-*pop_args(arg_stack_t* stack, int* argn, int* argc, char** argv[])
+* pop_args(arg_stack_t* stack, int* argn, int* argc, char** argv[])
 {
   arg_stack_t* res;
   char** argv2 = *argv;
@@ -238,10 +239,11 @@ main(int argc, char* argv[])
   queue* wpt_head_bak, *rte_head_bak, *trk_head_bak;   /* #ifdef UTF8_SUPPORT */
   signed int wpt_ct_bak, rte_ct_bak, trk_ct_bak;       /* #ifdef UTF8_SUPPORT */
   arg_stack_t* arg_stack = NULL;
+  (void) new gpsbabel::UsAsciiCodec(); /* make sure a US-ASCII codec is available */
 
 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
-  // Qt 5.0 uses QString::fromUtf8 to convert from character pointers 
-  // and QBytreArrays to QStrings while previous version of Qt used 
+  // Qt 5.0 uses QString::fromUtf8 to convert from character pointers
+  // and QBytreArrays to QStrings while previous version of Qt used
   // QString::fromAscii.  QString::fromAscii used the codec set
   // by QTextCode::setCodecForCStrings.
   // This makes the converstion consistent between Qt4 and Qt5.
@@ -320,10 +322,10 @@ main(int argc, char* argv[])
     }
 
     switch (c) {
-    //case 'c':
-    //  optarg = argv[argn][2] ? argv[argn]+2 : argv[++argn];
-    //  cet_convert_init(optarg, 1);
-    //  break;
+      //case 'c':
+      //  optarg = argv[argn][2] ? argv[argn]+2 : argv[++argn];
+      //  cet_convert_init(optarg, 1);
+      //  break;
     case 'i':
       optarg = argv[argn][2]
                ? argv[argn]+2 : argv[++argn];
diff --git a/gpsbabel/src/core/usasciicodec.cc b/gpsbabel/src/core/usasciicodec.cc
new file mode 100644 (file)
index 0000000..0654d96
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+    Copyright (C) 2014 Robert Lipe, gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include "usasciicodec.h"
+#include <QtCore/QByteArray>
+#include <QtCore/QChar>
+#include <QtCore/QLatin1Char>
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+// The availability of a US-ASCII codec is not promised by QTextCodec.
+// On Mac OS X is is likely one will not be available.
+// We provide our own to guarantee we have one.
+
+namespace gpsbabel
+{
+
+QByteArray UsAsciiCodec::name() const
+{
+  return "US-ASCII";
+}
+
+QList<QByteArray> UsAsciiCodec::aliases() const
+{
+  QList<QByteArray> list;
+  list += "iso-ir-6";
+  list += "ANSI_X3.4-1968";
+  list += "ANSI_X3.4-1986";
+  list += "ISO_646.irv:1991";
+  list += "ISO646-US";
+  list += "us";
+  list += "IBM367";
+  list += "cp367";
+  list += "csASCII";
+  return list;
+}
+
+int UsAsciiCodec::mibEnum() const
+{
+  return 3;
+}
+
+QString UsAsciiCodec::convertToUnicode(const char* chars, int len, ConverterState* state) const
+{
+  QString result(len, Qt::Uninitialized);
+  QChar* uc = result.data();
+  const unsigned char* c = (const unsigned char*)chars;
+  int invalid = 0;
+
+  for (int i = 0; i < len; i++) {
+    if (c[i] < 128) {
+      uc[i] = QLatin1Char(c[i]);
+    } else {
+      uc[i] = QChar::ReplacementCharacter;
+      ++invalid;
+    }
+  }
+
+  if (state) {
+    state->invalidChars += invalid;
+    state->remainingChars = 0;
+  }
+  return result;
+}
+
+QByteArray UsAsciiCodec::convertFromUnicode(const QChar* uc, int len, ConverterState* state) const
+{
+  QByteArray result(len, Qt::Uninitialized);
+  unsigned char* c = (unsigned char*)result.data();
+  const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
+  int invalid = 0;
+  int u;
+
+  for (int i = 0; i < len; i++) {
+    u = uc[i].unicode();
+    if (u < 128) {
+      c[i] = (char) u;
+    } else {
+      c[i] = replacement;
+      ++invalid;
+    }
+  }
+
+  if (state) {
+    state->invalidChars += invalid;
+    state->remainingChars = 0;
+  }
+  return result;
+}
+
+} // namespace gpsbabel
diff --git a/gpsbabel/src/core/usasciicodec.h b/gpsbabel/src/core/usasciicodec.h
new file mode 100644 (file)
index 0000000..602bb6e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2014 Robert Lipe, gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#ifndef QUSASCIICODEC_H
+#define QUSASCIICODEC_H
+
+#include <QtCore/QTextCodec>
+
+namespace gpsbabel
+{
+
+class UsAsciiCodec : public QTextCodec
+{
+public:
+  QByteArray name() const;
+  QList<QByteArray> aliases() const;
+  int mibEnum() const;
+  QString convertToUnicode(const char*, int, ConverterState*) const;
+  QByteArray convertFromUnicode(const QChar*, int, ConverterState*) const;
+};
+
+} // namespace gpsbabel
+#endif // QUSASCIICODEC_H